package com.shxy.service.impl;

import com.shxy.dao.wlzx.ModulDao;
import com.shxy.dao.wlzx.NewsDao;
import com.shxy.entity.wlzx.Modul;
import com.shxy.entity.wlzx.News;
import com.shxy.entity.user.User;
import com.shxy.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.List;

@Service
public class NewsService implements INewsService {
    @Autowired
    private NewsDao newsDao;
    @Autowired
    private ModulDao modulDao;

    @Override
    public News findNewsById(int id) {
        return newsDao.findById(id);
    }

    @Override
    public Modul getModulById(int id) {
        return modulDao.findById(id);
    }

    @Override
    public boolean isModulExist(int modulId) {
        return getModulById(modulId) != null;
    }

    @Override
    public int getNewsCountByModul(int modulId) {
        return newsDao.countAllByModulId(modulId);
    }

    @Override
    public List<News> getNewsOfModul(int modulId, int page, int size) {
        return newsDao.findAllByModulId(modulId, PageRequest.of(page - 1, size)).toList();
    }

    @Override
    public News saveNews(News news) {
        return newsDao.save(news);
    }

    @Override
    public boolean deleteNewsById(int id) {
        //newsDao.d
        return false;
    }
}
